<!--
  -    Copyright (c) 2018-2025, lengleng All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without
  - modification, are permitted provided that the following conditions are met:
  -
  - Redistributions of source code must retain the above copyright notice,
  - this list of conditions and the following disclaimer.
  - Redistributions in binary form must reproduce the above copyright
  - notice, this list of conditions and the following disclaimer in the
  - documentation and/or other materials provided with the distribution.
  - Neither the name of the pig4cloud.com developer nor the names of its
  - contributors may be used to endorse or promote products derived from
  - this software without specific prior written permission.
  - Author: lengleng (wangiegie@gmail.com)
  -->
<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        ref="crud"
        :page="page"
        :data="tableData"
        :permission="permissionList"
        :table-loading="tableLoading"
        :option="tableOption"
        @on-load="getList"
        @search-change="searchChange"
        @refresh-change="refreshChange"
        @size-change="sizeChange"
        @current-change="currentChange"
        @row-update="handleUpdate"
        @row-save="handleSave"
        @row-del="rowDel"
      >
        <template slot-scope="{ row, index, type, size }" slot="menu">
          <el-button v-if="row.roomState == '31'" :size="size" :type="type" icon="el-icon-view" @click.stop="killClick(row, index)">消杀登记</el-button>
          <el-button :size="size" :type="type" icon="el-icon-view" @click.stop="showClick(row, index)">查看</el-button>
        </template>
        <template slot-scope="{ row, index, type, size }" slot="useTypeSearch">
          <el-select v-model="customSearch.useType" clearable filterable placeholder="请选择使用类型">
            <el-option
              v-for="item in useTypeList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
      </avue-crud>
    </basic-container>
    <el-dialog title="查看" :visible.sync="dialogTableVisible" width="70%"  :close-on-click-modal	="false">
      <div v-if="dialogTableVisible">
        <el-tabs v-model="activeName">
          <el-tab-pane label="隔离点房间信息" name="details"></el-tab-pane>
          <el-tab-pane label="房间使用记录" name="child"></el-tab-pane>
          <el-tab-pane label="消杀情况登记" name="kill"></el-tab-pane>
        </el-tabs>
        <!-- <p style="font-size: 18px;font-weight: bold;margin: 0px 0px 5px;">隔离点房间信息</p>
            <el-divider class="custom-divider"></el-divider> -->
        <avue-form v-show="activeName == 'details'" name="details" class="custom-style" :option="tableOptionDetail" v-model="obj"></avue-form>

        <avue-crud
          v-show="activeName == 'child'"
          ref="childerCrud"
          :page="childPage"
          :data="gridData"
          :table-loading="HouseLoading"
          :option="childTableOption"
          @on-load="getPageMoveHouseRecord"
        ></avue-crud>
        <avue-crud
          v-show="activeName == 'kill'"
          ref="childerCrud"
          :page="keillPage"
          :data="killData"
          :table-loading="killLoading"
          :option="killRegistrationOption"
          @on-load="getKillList"
        ></avue-crud>
      </div>
    </el-dialog>
    <el-dialog title="消杀登记" :visible.sync="killRegistrationVisible" width="70%"  :close-on-click-modal	="false">
      <div v-if="killRegistrationVisible">
        <avue-form name="form" class="custom-style" :option="killRegistrationOption" v-model="killObj" @submit="killSave"></avue-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import mixinsCommon from '@/views/hotel/common/common-mixins.js';
import { fetchList, getObj, addObj, putObj, delObj, fetchListKill } from '@/views/hotel/api/jdglhotelhousexsqkinfo';
import { pageMoveHouseRecordVO } from '@/views/hotel/api/jdglhotelhouseinfo.js';
import { tableOption, childTableOption, killRegistrationOption } from '@/views/hotel/const/crud/jdglhotelhousexsqkinfo';
import { mapGetters,mapState } from 'vuex';

export default {
  name: 'jdglhotelhousexsqkinfo',
  mixins: [mixinsCommon],
  data() {
    return {
      activeName: 'kill',
      houseId: null,
      searchForm: {},
      customSearch:{
          useType:'21'
      },
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20 // 每页显示多少条
      },
      tableLoading: false,
      tableOption: tableOption,
      dialogTableVisible: false,
      HouseLoading: false,
      childTableOption: childTableOption,
      childPage: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      gridData: [],
      obj: {},
      killRegistrationVisible: false,
      killObj: {},
      killRegistrationOption: killRegistrationOption,
      keillPage: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      killLoading: false,
      killData: []
    };
  },
  computed: {
    ...mapGetters(['permissions']),
    ...mapState({
      useTypeList:state=>{
        return state.hotel.hotelDicts.use_type || []
      }
    }),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permissions.housexsqkinfo_add, false),
        delBtn: this.vaildData(this.permissions.housexsqkinfo_del, false),
        editBtn: this.vaildData(this.permissions.housexsqkinfo_edit, false)
      };
    },
    tableOptionDetail(){
      let ret = JSON.parse(JSON.stringify(this.tableOption));
      ret.detail = true;
      return ret;
    }
  },
  methods: {
    getList(page, params) {
      this.tableLoading = true;
      fetchList(
        Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize
          },
          params,
          this.searchForm,
          this.customSearch
        )
      )
        .then(response => {
          this.tableData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    rowDel: function(row, index) {
      this.$confirm('是否确认删除ID为' + row.xsqkInfoId, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(function() {
          return delObj(row.xsqkInfoId);
        })
        .then(data => {
          this.$message.success('删除成功');
          this.getList(this.page);
        });
    },
    handleUpdate: function(row, index, done, loading) {
      putObj(row)
        .then(data => {
          this.$message.success('修改成功');
          done();
          this.getList(this.page);
        })
        .catch(() => {
          loading();
        });
    },

    handleSave: function(row, done, loading) {
      addObj(row)
        .then(data => {
          this.$message.success('添加成功');
          done();
          this.getList(this.page);
        })
        .catch(() => {
          loading();
        });
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    currentChange(current) {
      this.page.currentPage = current;
    },
    searchChange(form, done) {
       this.page.currentPage=1;
      this.searchForm = form;
      this.getList(this.page, form);
      done();
    },
    refreshChange() {
      this.getList(this.page);
    },
    showClick(row, index) {
      this.obj = row;
      this.dialogTableVisible = true;
    },
    getPageMoveHouseRecord(page, params) {
      this.gridData = [];
      this.HouseLoading = true;
      pageMoveHouseRecordVO(
        Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize
          },
          params,
          { houseId: this.obj.houseId }
        )
      )
        .then(res => {
          this.gridData = res.data.data.records;
          this.childPage.total = res.data.data.total;
          this.HouseLoading = false;
        })
        .catch(err => {
          this.HouseLoading = false;
        });
    },
    killClick(row) {
      this.houseId = row.houseId;
      this.killRegistrationVisible = true;
    },
    killSave: function(row, done, loading) {
      addObj(Object.assign({ houseId: this.houseId }, row))
        .then(data => {
          this.$message.success('添加成功');

          this.getList(this.page);
          this.killRegistrationVisible = false;
          done();
        })
        .catch(() => {
          done();
          loading();
        });
    },
    getKillList(page, params) {
      this.killData = [];
      this.killLoading = true;
      fetchListKill(
        Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize,
            houseId: this.obj.houseId
          },
          params
        )
      )
        .then(response => {
          this.killData = response.data.data.records;
          this.killPage.total = response.data.data.total;
          this.killLoading = false;
        })
        .catch(() => {
          this.killLoading = false;
        });
    },
    async init() {
      let listHotelList = await this.listHotel({isSelf:1});
      this.getDicts().then(data => {
        let obj = {
          isValid: 'is_valid',
          useType: 'use_type',
          belongto:'hotel_street',
          roomState: 'room_state'
        };
        this.tableOption.column.map(item => {
          if (obj[item.prop]) {
            if (data[obj[item.prop]]) {
              item.dicData = data[obj[item.prop]];
            }
          } else if (item.prop == 'hotelBaseInfoId') {
            item.dicData = listHotelList;
          }
        });
        let child = {
          gender: 'gender',
          dataSource:'data_source',
          movePersonType:'move_person_type'
        };
        this.childTableOption.column.map(item => {
          if (child[item.prop]) {
            if (data[child[item.prop]]) {
              item.dicData = data[child[item.prop]];
            }
          }
        });
      });
    }
  },
  created() {
    this.init();
  }
};
</script>
